package 剑指offer;

import common.ListNode;

/**
 * @author zhangjunfei
 * @date 2023/7/20 16:43
 */
public class O_22 {
    public ListNode getKthFromEnd(ListNode head, int k) {

        ListNode temp = head;

        int count = 0;
        while (temp != null) {
            count++;
            temp = temp.next;
        }
        temp = head;
        int index = 0;
        while (temp != null) {
            if (count - k == index) {
                return temp;
            }
            index++;
            temp = temp.next;
        }
        return null;

    }
}
